<template>
    <IContent :spinShow="loading">
        <ISearch v-model="search">
            <FormItem :label-width="1">
                <Button type="primary" icon="ios-search" @click="getLists(1)" size="small">搜索</Button>
                <Button type="success" icon="ios-add" @click="openComponent('ICreate')" size="small">添加</Button>
            </FormItem>
        </ISearch>
        <ITable :current="page.current" :table="table" :total="page.total" @on-page-change="pageChange">
            <template slot-scope="{ row, index }" slot="volume">
                <span>{{row.length}} x {{row.width}} x {{row.height}}</span>
            </template>
            <template slot-scope="{ row, index }" slot="action">
                <Button size="small" @click="openComponent('IUpdate', {id: row.id})">编辑</Button>
                <Button size="small" @click="openComponent('IStock',  {id: row.id})">库存</Button>
                <Button size="small" @click="openComponent('IIView',  {id: row.id})">查看</Button>
            </template>
        </ITable>

        <component v-if="componentProps.value" :is="componentProps.view" v-model="componentProps.value"
                   :props="componentProps.props"
                   @input="getLists(page.current)"></component>
    </IContent>
</template>

<script>
    import contentListPage from "../../../mixins/contentListPage";
    import IContent from "../../../components/content/index";
    import ISearch from "../../../components/content/search";
    import ITable from "../../../components/content/table";
    import contentDrawer from "../../../mixins/contentDrawer";
    import IUpdate from "./update"
    import ICreate from "./create"
    import IStock from "./stock"
    import IIView from "./view"
    import RemoteSelect from "../../../components/form/remoteSelect";

    export default {
        name: "index",
        components: {RemoteSelect, ITable, ISearch, IContent, IUpdate, ICreate, IStock, IIView},
        mixins: [contentListPage, contentDrawer],
        data() {
            return {
                table: {
                    columns: [
                        {
                            title: '耗材名称',
                            key: 'name'
                        },
                        {
                            title: '耗材报价',
                            key: 'price'
                        }, {
                            title: '耗材库存',
                            key: 'stock'
                        },{
                            title: '耗材毛重',
                            key: 'weight'
                        },{
                            title: '长x宽x高',
                            slot: 'volume'
                        },
                        {
                            title: '耗材说明',
                            key: 'remark'
                        },
                        {
                            title: '操作',
                            slot: 'action'
                        }
                    ]
                },
                search: {}
            }
        },
        methods: {
            getLists(page) {
                this.loading = true;
                this.$http.get(`warehouse/consumable`, {
                    params: Object.assign({}, this.search, {page: page})
                }).then((data) => {
                    this.table.data = data.data
                    this.page.total = data.total
                    this.page.current = data.current_page
                }).finally(() => {
                    this.loading = false;
                });
            }
        }
    }
</script>

<style scoped>

</style>
